package lambda;

import java.util.HashMap;
import java.util.Map;

public class MxIfAbsent {
    public static void main(String[] args) {
        Map<String, Bean> map = new HashMap<>();
        map.put("M1", new Bean("M1", 1d));
        map.put("M2", new Bean("M2", 2d));
        // ComputeIfAbsent
        Bean bean = map.computeIfAbsent("M3", k -> new Bean("M3", 3d));
        System.out.println(bean);
        System.out.println(map.get("M3"));

        // PutIfAbsent
        bean = map.putIfAbsent("M4", new Bean("M4", 4d));
        System.out.println(bean);
        System.out.println(map.get("M4"));
    }
}
